package com.business.system.official.toursism.websitenews.manager.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.business.system.official.toursism.websitenews.entity.WebsiteNews;
import com.business.system.official.toursism.websitenews.manager.WebsiteNewsManager;
import com.business.system.official.toursism.websitenews.mapper.WebsiteNewsMapper;
import com.business.system.official.toursism.websitenews.vo.WebsiteNewsBriefListVO;
import com.business.system.official.toursism.websitenews.vo.WebsiteNewsBriefVO;
import com.business.system.official.toursism.websitenews.vo.WebsiteNewsDetailListVO;
import com.business.system.official.toursism.websitenews.vo.WebsiteNewsDetailVO;
import com.business.system.official.toursism.websitenews.vo.data.WebsiteNewsBriefData;
import com.business.system.official.toursism.websitenews.vo.data.WebsiteNewsDetailData;
import com.seed.core.exception.ManagerException;
import com.seed.core.pojo.manager.impl.SeedSystemManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 乌镇新闻
 * @author CodeGenerator
 * @date   2025-01-25
 * @version V1.0
 */
@Slf4j
@Transactional(rollbackFor = ManagerException.class)
@Service("websiteNewsManager")
public class WebsiteNewsManagerImpl extends SeedSystemManagerImpl<WebsiteNewsMapper, WebsiteNews> implements WebsiteNewsManager {

    /**
     * 根据id获取详情VO data
     *
     * @param websiteNewsId 对象id
     * @return 详情VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsDetailData convertDetailData(String websiteNewsId) throws ManagerException {
        WebsiteNews websiteNews = this.getById(websiteNewsId);
        return this.convertDetailData(websiteNews);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNews model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsDetailData convertDetailData(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsDetailData websiteNewsDetailData = new WebsiteNewsDetailData();
        try {
            BeanUtils.copyProperties(websiteNews, websiteNewsDetailData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteNews);
        }
        return websiteNewsDetailData;
    }

    /**
     * 根据id获取详情VO
     *
     * @param websiteNewsId 对象id
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsDetailVO getDetailVO(String websiteNewsId) throws ManagerException {
        WebsiteNewsDetailData websiteNewsDetailData = this.convertDetailData(websiteNewsId);
        return new WebsiteNewsDetailVO(websiteNewsDetailData);
    }

    /**
     * 根据对象获取详情VO
     *
     * @param websiteNews 对象
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsDetailVO getDetailVO(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsDetailData websiteNewsDetailData = this.convertDetailData(websiteNews);
        return new WebsiteNewsDetailVO(websiteNewsDetailData);
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsDetailData> getConvertDetailListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteNews> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteNews::getId, ids);
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteNewsList);
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsDetailData> listConvertDetailData(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteNewsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNewsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsDetailData> listConvertDetailData(List<WebsiteNews> websiteNewsList) throws ManagerException {
        List<WebsiteNewsDetailData> websiteNewsDetailDataList = new ArrayList<>();
        for (WebsiteNews websiteNews : websiteNewsList) {
            websiteNewsDetailDataList.add(this.convertDetailData(websiteNews));
        }
        return websiteNewsDetailDataList;
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsDetailListVO getDetailListVOByIds(List<String> ids) throws ManagerException {
        return new WebsiteNewsDetailListVO(this.getConvertDetailListVOByIds(ids));
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsDetailListVO getDetailListVO(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        return new WebsiteNewsDetailListVO(this.listConvertDetailData(queryWrapper));
    }

    /**
     * 根据对象list获取详情VO data list
     *
     * @param websiteNewsList 对象list
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsDetailListVO getDetailListVO(List<WebsiteNews> websiteNewsList) throws ManagerException {
        return new WebsiteNewsDetailListVO(this.listConvertDetailData(websiteNewsList));
    }

    /**
     * 根据id获取简略VO data
     *
     * @param websiteNewsId 对象id
     * @return 简略VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsBriefData convertBriefData(String websiteNewsId) throws ManagerException {
        WebsiteNews websiteNews = this.getById(websiteNewsId);
        return this.convertBriefData(websiteNews);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNews model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsBriefData convertBriefData(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsBriefData websiteNewsBriefData = new WebsiteNewsBriefData();
        try {
            BeanUtils.copyProperties(websiteNews, websiteNewsBriefData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteNews);
        }
        return websiteNewsBriefData;
    }

    /**
     * 根据id获取简略VO
     *
     * @param websiteNewsId 对象id
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsBriefVO getBriefVO(String websiteNewsId) throws ManagerException {
        WebsiteNewsBriefData websiteNewsBriefData = this.convertBriefData(websiteNewsId);
        return new WebsiteNewsBriefVO(websiteNewsBriefData);
    }

    /**
     * 根据对象获取简略VO
     *
     * @param websiteNews 对象
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsBriefVO getBriefVO(WebsiteNews websiteNews) throws ManagerException {
        WebsiteNewsBriefData websiteNewsBriefData = this.convertBriefData(websiteNews);
        return new WebsiteNewsBriefVO(websiteNewsBriefData);
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsBriefData> listConvertBriefDataByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteNews> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteNews::getId, ids);
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteNewsList);
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsBriefData> listConvertBriefData(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteNewsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteNewsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteNewsBriefData> listConvertBriefData(List<WebsiteNews> websiteNewsList) throws ManagerException {
        List<WebsiteNewsBriefData> websiteNewsBriefDataList = new ArrayList<>();
        for (WebsiteNews websiteNews : websiteNewsList) {
            websiteNewsBriefDataList.add(this.convertBriefData(websiteNews));
        }
        return websiteNewsBriefDataList;
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsBriefListVO getBriefListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteNews> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteNews::getId, ids);
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return new WebsiteNewsBriefListVO(this.listConvertBriefData(websiteNewsList));
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsBriefListVO getBriefListVO(Wrapper<WebsiteNews> queryWrapper) throws ManagerException {
        List<WebsiteNews> websiteNewsList = this.list(queryWrapper);
        return new WebsiteNewsBriefListVO(this.listConvertBriefData(websiteNewsList));
    }

    /**
     * 根据对象list获取简略VO data list
     *
     * @param websiteNewsList 对象list
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteNewsBriefListVO getBriefListVO(List<WebsiteNews> websiteNewsList) throws ManagerException {
        return new WebsiteNewsBriefListVO(this.listConvertBriefData(websiteNewsList));
    }
}
